package hessian.client;   
  
import hessian.service.LuceneService;
import hession.model.LuceneDocument;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

import com.caucho.hessian.client.HessianProxyFactory;
  
/**  
 *  
 * @author absolute  
 */  
public class LuceneClient {   
       
    private String url = "http://localhost:8080/HessianTest/lucene";   
       
    public LuceneService getService() throws MalformedURLException {   
        HessianProxyFactory factory = new HessianProxyFactory();              
        return  (LuceneService) factory.create(LuceneService.class, url);   
    }   
       
    public static void main(String[] args) {   
        LuceneClient client = new LuceneClient();   
        try {   
        	LuceneService service = client.getService();
        	service.doReload();
        	HashMap<String, Object> map = new HashMap<String, Object>();
        	map.put("field", "id");
        	map.put("keyword", "10099");
            ArrayList<LuceneDocument> doUpdate = service.doSelect(map);
            System.out.println(doUpdate.size());
            for (LuceneDocument luceneDocument : doUpdate) {
				System.out.println(luceneDocument);
			}
            
            HashMap<String,String> doc = new HashMap<String,String>();
            doc.put("id", "10099");
            doc.put("path", "/home/");
            service.doUpdate(doc);
            service.doCommit();
            
        } catch (Exception e) {   
            e.printStackTrace();   
        }   
    }   
}   